package ui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;

@SuppressWarnings("serial")
public class ScenarioOriginatorHostComponent extends JPanel {
	// Variables
		
	private HostPartToolbar hpt = new HostPartToolbar();
	private BorderLayout layout = new BorderLayout();
	private ScenarioOriginatorHostComponentSplitPane sp = null; 
		
		
	// Methods
	public ScenarioOriginatorHostComponent(ScenarioOriginatorIFrame par) {
		super();
		sp = new ScenarioOriginatorHostComponentSplitPane(par);
		this.setLayout(layout);
		this.add(hpt, BorderLayout.NORTH);
		this.add(sp, BorderLayout.CENTER);
	}



	public Vector<Vector<String>> getHosts() {
		return sp.getHosts();
	}



	
	class HostPartToolbar extends JToolBar {
		private JButton addHost = null;
		private String addHostButtonTitle = "Add Host";
		private JButton deleteHost = null;
		private String deleteHostButtonTitle = "Del Host";
		private JButton updateGrafics = null;
		private String updateGraficsButtonTitle = "Update Grafik";

		private JButton getUpdateGrafics() {
			if (updateGrafics == null) {
				updateGrafics = new JButton(updateGraficsButtonTitle);
				updateGrafics.addActionListener(new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent arg0) {
						sp.updateGraphic();
				}

				});
			}
			return updateGrafics;
		}

		private JButton getAddHostButton() {
			if (addHost == null) {
				addHost = new JButton(addHostButtonTitle);
				addHost.addActionListener(new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent arg0) {
						sp.addHost();
					}

				});
			}
			return addHost;
		}

		private JButton getDeleteHostButton() {
			if (deleteHost == null) {
				deleteHost = new JButton(deleteHostButtonTitle);
				deleteHost.addActionListener(new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent arg0) {
						sp.deleteHost();
					}

				});
			}
			return deleteHost;
		}


		// Methods
		public HostPartToolbar() {
			super();
			this.add(this.getAddHostButton());
			this.add(this.getDeleteHostButton());
			this.add(this.getUpdateGrafics());
		}

	}

}
